﻿using System;
using System.Xml;

namespace Jayden.Dll.Core.Persistence.Xml
{
	public class XmlNodeProxy: IDisposable
	{
		private XmlDocumentLock m_DocumentLock;
		private XmlNode m_Node;
		private bool m_WriteAccess;

		public XmlNodeProxy(XmlDocumentLock docLock, XmlNode node, bool writeAccess)
		{
			m_DocumentLock = docLock;
			m_Node = node;
			m_WriteAccess = writeAccess;
		}

		public XmlNode Node { get { return m_Node; } }
		public bool WriteAccess { get { return m_WriteAccess; } }

		public void Dispose()
		{
			if (m_Node != null)
				m_Node = null;
			if (m_DocumentLock != null)
			{
				m_DocumentLock.ReleaseDocument(m_WriteAccess);
				m_DocumentLock = null;
			}
		}
	}
}
